/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isil.tia.dao.hibernate;

import com.isil.tia.dao.NominaDao;
import com.isil.tia.domain.Nomina;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Soain01
 */
public class NominaDaoHibernate implements NominaDao {

    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void add(Nomina nomina) {
        sessionFactory.getCurrentSession().save(nomina);
    }

    @Override
    public Nomina get(Integer id) {
        return (Nomina) sessionFactory.getCurrentSession().get(Nomina.class, id);
    }

    @Override
    public Nomina getByIdEmpleado(Integer id) {
        return (Nomina) sessionFactory.getCurrentSession().createCriteria((Nomina.class)).add(Restrictions.eq("id_empleado", id)).uniqueResult();
    }

    @Override
    public List<Nomina> loadAll() {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Nomina.class);
        return criteria.list();
    }

    @Override
    public void update(Nomina nomina) {
        sessionFactory.getCurrentSession().update(nomina);
    }

    @Override
    public void delete(Integer id) {
        sessionFactory.getCurrentSession().delete(id);
    }
    
    @Override
    public void deleteByIdEmpleado(Integer id){
        String hql = "delete from Nomina where id_empleado= :id_empleado";
        sessionFactory.getCurrentSession().createQuery(hql).setInteger("id_empleado", id).executeUpdate();
    }
}
